package com.mobinters.cafeman.adapter;

import java.util.List;

import com.mobinters.cafeman.R;
import com.mobinters.cafeman.object.AreaItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class AreaAdapter extends BaseAdapter{

	List<AreaItem> mData;
	Context mContext;
	LayoutInflater mInflater;
	
	public AreaAdapter(Context context,List<AreaItem> data){
		mContext = context;
		mData = data;
		mInflater =  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView == null){
			convertView = mInflater.inflate(R.layout.dlg_area_item, parent, false);
		}
		AreaItem item = mData.get(position);
		TextView tv = (TextView) convertView.findViewById(R.id.txt_area_name);
		tv.setText(item.Name);
		final CheckBox cb = (CheckBox) convertView.findViewById(R.id.cb_area);
		cb.setChecked(item.Checked);
		
		cb.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mData.get(position).Checked = cb.isChecked();
				
			}
		});
		
		
		return convertView;
	}

}
